package com.alisls.demo.springcloud.service.im.service.impl;

import com.alisls.demo.springcloud.service.im.service.RabbitMqMessageService;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 描述信息
 *
 * @author Ke Wang
 * @date 2020/10/14
 */
@Service("rabbitMqMessageService")
public class RabbitMqMessageServiceImpl implements RabbitMqMessageService {

    @Resource
    private AmqpTemplate amqpTemplate;

    /**
     * 发送消息
     * 发送到默认的交换器和路由键
     * @param message
     * @return
     */
    @Override
    public String sendMessage(String message) {
        amqpTemplate.convertAndSend(message);
        return "ok";
    }

    /**
     * 发送消息
     * 发送到默认的交换器和指定的路由键
     * @param routingKey
     * @param message
     * @return
     */
    @Override
    public String sendMessage(String routingKey, String message) {
        amqpTemplate.convertAndSend(routingKey, message);
        return "ok";
    }

    /**
     * 发送消息到指定交换器，指定路由键
     * @param exchange
     * @param routingKey
     * @param message
     * @return
     */
    @Override
    public String sendMessage(String exchange, String routingKey, String message) {
        amqpTemplate.convertAndSend(exchange, routingKey, message);
        return "ok";
    }

}
